﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="paringesindus_v2_ettevote", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(ParingesindusV2Ettevote))]
    public class ParingesindusV2EttevoteSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IParingesindusV2Ettevote clazz;
        
        public ParingesindusV2EttevoteSerializer(IParingesindusV2Ettevote clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("ariregistri_kood");
            if (clazz.AriregistriKood!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.AriregistriKood))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("arinimi");
            if (clazz.Arinimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Arinimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Arinimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("staatus");
            if (clazz.Staatus!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Staatus))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Staatus");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("staatus_tekstina");
            if (clazz.StaatusTekstina!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.StaatusTekstina))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : StaatusTekstina");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("isikud");
            if (clazz.Isikud!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("paringesindus_isik", "http://producers.arireg.xtee.riik.ee/producer/arireg", clazz.Isikud.Count);
                for (int x = 0; ((clazz.Isikud != null) 
                            && (x < clazz.Isikud.Count)); x = (x + 1)) {
                    if (clazz.Isikud[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaIsikud = this.GetMetaData(clazz.Isikud[x]);
                        Writer.WriteTypeAttribute(metaIsikud.TypeQualifiedName.Namespace, metaIsikud.TypeQualifiedName.Name);
                        metaIsikud.NewSerializer(clazz.Isikud[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Isikud");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("esindusoiguse_eritingimused");
            if (clazz.EsindusoiguseEritingimused!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("paringesindus_eritingimus", "http://producers.arireg.xtee.riik.ee/producer/arireg", clazz.EsindusoiguseEritingimused.Count);
                for (int x = 0; ((clazz.EsindusoiguseEritingimused != null) 
                            && (x < clazz.EsindusoiguseEritingimused.Count)); x = (x + 1)) {
                    if (clazz.EsindusoiguseEritingimused[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaEsindusoiguseEritingimused = this.GetMetaData(clazz.EsindusoiguseEritingimused[x]);
                        Writer.WriteTypeAttribute(metaEsindusoiguseEritingimused.TypeQualifiedName.Namespace, metaEsindusoiguseEritingimused.TypeQualifiedName.Name);
                        metaEsindusoiguseEritingimused.NewSerializer(clazz.EsindusoiguseEritingimused[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : EsindusoiguseEritingimused");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("oiguslik_vorm");
            if (clazz.OiguslikVorm!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OiguslikVorm))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : OiguslikVorm");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("oiguslik_vorm_tekstina");
            if (clazz.OiguslikVormTekstina!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OiguslikVormTekstina))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : OiguslikVormTekstina");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ariregistri_kood") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AriregistriKood = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("ariregistri_kood")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringesindus_v2_ettevote>ariregistri_kood", Reader.LocalName);
            }
            if (Reader.LocalName=="arinimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringesindus_v2_ettevote>arinimi");
                }
                clazz.Arinimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("arinimi")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringesindus_v2_ettevote>arinimi", Reader.LocalName);
            }
            if (Reader.LocalName=="staatus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringesindus_v2_ettevote>staatus");
                }
                clazz.Staatus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("staatus")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringesindus_v2_ettevote>staatus", Reader.LocalName);
            }
            if (Reader.LocalName=="staatus_tekstina") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringesindus_v2_ettevote>staatus_tekstina");
                }
                clazz.StaatusTekstina = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("staatus_tekstina")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringesindus_v2_ettevote>staatus_tekstina", Reader.LocalName);
            }
            if (Reader.LocalName=="isikud") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringesindus_v2_ettevote>isikud");
                }
                clazz.Isikud = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParingesindusIsik>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("isikud");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringesindus_isikud>item");
                        }
                        global::Xtee.Core.SerializationMetadata metaIsikud = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParingesindusIsik>(Reader, "paringesindus_isik", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                        global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParingesindusIsik item = metaIsikud.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParingesindusIsik>();
                        clazz.Isikud.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("item");
                            metaIsikud.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringesindus_v2_ettevote>isikud", Reader.LocalName);
            }
            if (Reader.LocalName=="esindusoiguse_eritingimused") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringesindus_v2_ettevote>esindusoiguse_eritingimused");
                }
                clazz.EsindusoiguseEritingimused = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParingesindusEritingimus>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("esindusoiguse_eritingimused");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringesindus_eritingimused>item");
                        }
                        global::Xtee.Core.SerializationMetadata metaEsindusoiguseEritingimused = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParingesindusEritingimus>(Reader, "paringesindus_eritingimus", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                        global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParingesindusEritingimus item = metaEsindusoiguseEritingimused.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParingesindusEritingimus>();
                        clazz.EsindusoiguseEritingimused.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("item");
                            metaEsindusoiguseEritingimused.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringesindus_v2_ettevote>esindusoiguse_eritingimused", Reader.LocalName);
            }
            if (Reader.LocalName=="oiguslik_vorm") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringesindus_v2_ettevote>oiguslik_vorm");
                }
                clazz.OiguslikVorm = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("oiguslik_vorm")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringesindus_v2_ettevote>oiguslik_vorm", Reader.LocalName);
            }
            if (Reader.LocalName=="oiguslik_vorm_tekstina") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringesindus_v2_ettevote>oiguslik_vorm_tekstina");
                }
                clazz.OiguslikVormTekstina = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("oiguslik_vorm_tekstina")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringesindus_v2_ettevote>oiguslik_vorm_tekstina", Reader.LocalName);
            }
        }
    }
}
